﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.Charting;
using Telerik.Windows.Controls;
using System.Windows.Threading;

namespace DIST.LR.ZHJG.Controls.Chart
{
    public partial class ucBar : UserControl
    {
        public ucBar()
        {
            InitializeComponent();
        }

        public void Binding<T>(BarInfo<T> barinfo)
        {
            this.RadChart1.SeriesMappings.Clear();
            SeriesMapping mapping = new SeriesMapping();
            mapping.SeriesDefinition = new HorizontalBarSeriesDefinition()
            {
                ShowItemToolTips = true,
                ShowItemLabels = true,
                LabelSettings = new BarLabelSettings()
                {
                    Distance = 10,
                    LabelDisplayMode = Telerik.Windows.Controls.Charting.LabelDisplayMode.Outside,
                    ShowZeroValueLabels = true,
                    ShowConnectors = false
                },
                Appearance = new SeriesAppearanceSettings() { Fill = barinfo.BarSetting.Color },
                SeriesItemLabelStyle = this.Resources["SeriesItemLabelStyle"] as Style
            };
            mapping.LegendLabel = barinfo.BarSetting.LableName;
            mapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.YValue, FieldName = barinfo.BarSetting.ValueName });
            mapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.XCategory, FieldName = barinfo.BarSetting.XCategoryName });
            this.RadChart1.SeriesMappings.Add(mapping);
            this.RadChart1.ItemsSource = barinfo.DataSource;
        }
    }

    public class BarInfo<T>
    {
        public BarValue BarSetting { get; set; }
        public List<T> DataSource { get; set; }
    }

    public class BarValue
    {
        public string LableName { get; set; }
        public string ValueName { get; set; }
        public string XCategoryName { get; set; }
        public SolidColorBrush Color { get; set; }
    }
}
